package com.b2j.language;

import com.b2j.base.ErrorManager;
import com.b2j.base.Lexema;
import com.b2j.base.MainTools;
import com.b2j.base.ProcessData;
import com.b2j.base.Routine;
import com.b2j.base.Token;

public class Process extends Routine {

	@Override
	public String generate(Lexema lexema) {
		
		String line = "";
		lexema = MainTools.tools.nextLexema();
		if (lexema.tokenType == Token.ID) {
			
			String name = lexema.lexema;
//			ProcessData p = MainTools.tools.process.get(name);
			ProcessData p = MainTools.tools.getProcess(name);
			
			MainTools.tools.parseTo(Token.BEGIN);
			
			if (p != null) {

				// Main method
				line = "@Override\npublic void code() throws InterruptedException {\n";
				// Process the code inside the block of PROCESS
				line = line + MainTools.tools.processCodeUntil(lexema, Token.END) + "}\n";
			
				// Dispose method
				line = line + "@Override\npublic void dispose() {\n// TODO Auto-generated method stub\n}\n";
				
				p.code = line;
				
			}
		} else {
			ErrorManager.unexpected(lexema);
		}
		
		return line;
	}

	

}
